package com.example.blogapi.controller;

import com.example.blogapi.common.aop.LogAnnotation;
import com.example.blogapi.domain.MsTag;
import com.example.blogapi.domain.dos.Archives;
import com.example.blogapi.service.MsArticleService;
import com.example.blogapi.vo.ArticleVo;
import com.example.blogapi.vo.Result;
import com.example.blogapi.vo.param.ArticleParam;
import com.example.blogapi.vo.param.PageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags= {"用户管理"})
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    MsArticleService msArticleService;

    @PostMapping()
    /*swagger注解*/
    @ApiOperation(value = "分页查询用户",notes = "通过页数和每页数据的多少分页")
//    @ApiImplicitParam(name = "pageParam",value = "分页对象",required = true,paramType="query")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "pageParam",value = "页数",required = true,paramType = "body",dataType = "String")
//    })

    /*日志注解*/
    @LogAnnotation(module = "查询文章",operation = "分页查询所有文章数据")
    /**
     * 所有文章
     *
     */
    public Result listArticle(@RequestBody PageParam pageParam){
        //ArticleVo 页面接收的数据
        List<ArticleVo> articles = msArticleService.listArticlesPage(pageParam);
        return Result.success(articles);
    }
    @PostMapping("/hot")
    /**
     * 热门文章
     */
    public Result getHotArticles(){
        int limit = 6;
        List<ArticleVo> hotArticles = msArticleService.getHotArticles(limit);
        return Result.success(hotArticles);

    }

    /**
     * 最新文章
     * @return
     */
    @PostMapping("/new")
    public Result getNewArticles(){
        int limit = 6;
        List<ArticleVo> hotArticles = msArticleService.getNewArticles(limit);
        return Result.success(hotArticles);

    }

    /**
     * 时间档案
     * @return
     */
    @PostMapping("/archives")
    public Result listArchives(){
        List<Archives> archives = msArticleService.listArchives();
        return Result.success(archives);
    }

    /**
     * 根据id查找文章
     * @param id
     * @return
     */
    /*swagger注解*/
    @ApiOperation(value = "查询文章",notes = "通过id查询单个文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "文章编号",required = true,paramType = "path",dataType = "Integer")
    })
    @PostMapping("/view/{id}")
    public Result findArticleById(@PathVariable("id") Long id) {
        ArticleVo articleVo = msArticleService.findArticleById(id);

        return Result.success(articleVo);
    }

    /**
     * 发布文章
     * @param articleParam
     * @return
     */
    @PostMapping("/publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return msArticleService.publish(articleParam);
    }
}
